<?php
/**
 * Definition d'un ecran d'application
 * @author Micou13630
 *
 */
class Screen extends Layout implements IRenderable {

	private $title;
	
	private $css;
	private $js;
	
	private $ds;
	
	private $window;

	/**
	 * Constrcuteur
	 */
	public function Screen($title = "") {
		parent::Layout();

		$this->ID 		= Config::getParams()->ID_SCREEN;
		$this->vertical = true;
		$this->top 		= 0;
		$this->left 	= 0;
		$this->width 	= '100%';
		$this->height 	= '100%';
		$this->padding 	= 0;
		$this->overflow = Constant::OVERFLOW_HIDDEN;
		
		$this->title 	= $title;
		
		$this->css		= array();
		$this->js		= array();
		
		$this->ds		= array();
		
		$this->window	= array();
	}
	
	/**
	 * Permet d'ajouter un dataSource global au context screen
	 * Enter description here ...
	 */
	public function addDatasource(DataSource $dataSource) {
		$this->ds[] = $dataSource;
	}

	/**
	 * Permet d'ajouter des fenetres
	 * Enter description here ...
	 */
	public function addWindow(Window $wind) {
		$this->window[] = $wind;
	}
	
	/**
	 * Permet d'ajouter une css
	 * Enter description here ...
	 */
	public function addCss($cssPath) {
		$this->css[] = $cssPath;
	}

	/**
	 * Permet d'ajouter une js
	 * Enter description here ...
	 */
	public function addJs($jsPath) {
		$this->js[] = $jsPath;
	}
	
	/**
	 * Implementation de object
	 * @see IRenderable::object()
	 */
	public function object() {
		return "Layout";
	}

	/**
	 * Implementation de properties
	 * @see IRenderable::properties()
	 */
	public function properties() {
		return parent::properties();
	}
	
	/**
	 * Implementation de scLog
	 * @see IRenderable::scLog()
	 */
	public function scLog() {
		ScCollectionLog::getInstance()->addSc(new ScLog($this->object(), get_object_vars($this)));
	}
	
	/**
	 * Implementation de display
	 * @see IScreen::display()
	 */
	public function render() {
		$this->scLog();
		
		$str_out = "<html>";
		$str_out.= "<head>";
		$str_out.= "<title>".$this->title."</title>";
		$str_out.= "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />";
		$str_out.= "<script type=\"text/javascript\">var isomorphicDir=\"".Config::getParams()->PATH_ISOMORPHIC."\";</script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Core.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Foundation.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Containers.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Grids.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Forms.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_Calendar.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_RichTextEditor.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_DataBinding.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_MODULES."ISC_History.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_SKINS.Config::getParams()->SKIN."/load_skin.js\" type=\"text/javascript\"></script>";
		$str_out.= "<script src=\"".Config::getParams()->PATH_LOCALES."frameworkMessages_".Config::getParams()->LANG.".properties\" type=\"text/javascript\"></script>";
		
		foreach ($this->js as $script)
			$str_out.= "<script src=\"".$script."\" type=\"text/javascript\"></script>";
		
		foreach ($this->css as $style)
			$str_out.= "<link type=\"text/css\" rel=\"stylesheet\" href=\"".$style."\"/>";
		
		$str_out.= "</head>";
		$str_out.= "<body>";
		$str_out.= "<script>";
		
		// Traitement des dataSources
		foreach ($this->ds as $ads) {
			$str_out.= $ads->render().";";
		}
		
		$str_out.= "isc.".$this->object().".create({".$this->properties()."});";

		// Traitement de la console
		if (Config::getParams()->CONSOLE) {
			$con = new Console('#console#', '- CONSOLE -');
			$str_out.= $con->render();
		}

		// Traitement des windows
		foreach ($this->window as $w) {
			$str_out.= $w->render().";";
		}
		
		$str_out.= "</script>";
		$str_out.= "</body>";
		$str_out.= "</html>";

		echo $str_out;
	}
}
?>
